<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/static/admin/jsp/include.jsp"%>
    <style type="text/css">
        .textbox.textbox-focused .textbox-addon,
        .textbox.textbox-focused .textbox-text{
            background: #eee!important;
        }
    </style>
    <script type="text/javascript">
        var id = "${id}";

        submitForm = function($dialog, $grid, $pjq) {
            if ($('form').form('validate')) {
                var obj=sy.serializeObject($('form'));
                var url=sy.contextPath + '/chemicalType/save';
                var type = $("#type").combobox("getValue");
                if(type == 1){
                    obj.rangeInfo = $("#rangeInfos").combobox("getValue");
                }else if(type == 2){

                    obj.rangeInfo = $("#rangeInfo").textbox("getValue");
                }
                obj.type = $("#type").combobox("getValue");
                obj.info = editor.getHtml();
                $.post(sy.contextPath + '/chemicalType/isExist', obj, function(data) {
                    if (data.code == 0) {
                        parent.$.messager.confirm('询问', '确定保存？', function(r) {
                            if (r) {
                                $.post(url, obj, function(result) {
                                    if (result.code == 0) {
                                        parent.$.messager.i('保存成功');
                                        $grid.datagrid('reload');
                                        $dialog.dialog('destroy');
                                    } else {
                                        $pjq.messager.e('保存失败,'+result.msg);
                                    }
                                }, 'json');
                            }
                        });
                    } else {
                        $pjq.messager.e('保存失败,'+data.msg);
                    }
                }, 'json');




            }
        };

        $(function() {
            editor = new HtmlEditor('#info');
            $("#rangeParam").hide();
            $("#rangeParam1").hide();
            $("#rangeParam2").show();
            $("#type").combobox({
                onChange: function (newValue, oldValue) {
                    if(newValue == 1){
                        //阴阳
                        $("#rangeParam").hide();
                        $("#rangeParam1").hide();
                        $("#rangeParam2").show();
                    }else if(newValue == 2){
                        //数值
                        $("#rangeParam2").hide();
                        $("#rangeParam").show();
                        $("#rangeParam1").show();
                    }

                }

            });

            if(id != ''){
                $.post(sy.contextPath + '/chemicalType/findById', {
                    id : id,
                }, function(result) {
                    if (id != '') {
                        parent.$.messager.progress({
                            text : '数据加载中....'
                        });
                        $.post(sy.contextPath + '/chemicalType/findById', {
                            id : id
                        }, function(result) {
                            console.log(result)
                            if (result) {
                                if(result.type == 1){
                                    $("#rangeParam").hide();
                                    $("#rangeParam1").hide();
                                    $("#rangeParam2").show();
                                    $("#rangeInfos").combobox("setValue",result.rangeInfo);
                                }else if(result.type == 2){
                                    $("#rangeParam2").hide();
                                    $("#rangeParam").show();
                                    $("#rangeParam1").show();
                                    $("#rangeInfo").textbox("setValue",result.rangeInfo);
                                }
                                editor.setHtml(result.info);
                                $('form').form('load', result);
                            }
                            parent.$.messager.progress('close');
                        }, 'json');

                    }
                })
            }
        });

    </script>
</head>
<body>
<form id="form" method="post">
    <input name="id" type="hidden" />
    <div style="padding:15px;font-size: 12px">
        <table style="table-layout:fixed;" border="0" cellspacing="0" class="formtable">
            <tr>
                <th style="width:100px;">类型：</th>
                <td colspan="3">
                    <select id="type" class="easyui-combobox" name="type" data-options="required:true,editable:false">
                        <option value="1">阴阳型</option>
                        <option value="2">数值型</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th style="width:100px;">元素中文名：</th>
                <td>
                    <input id="name" name="name" class="easyui-textbox" missingMessage="请输入" prompt="请输入" style="width:90%;"
                           data-options="required:true"/>
                </td>
                <th style="width:100px;">对应元素符号：</th>
                <td>
                    <input id="chemicalName" name="chemicalName" class="easyui-textbox" missingMessage="请输入" prompt="请输入" style="width:90%;"
                           data-options="required:true" />
                </td>
            </tr>

            <tr>
                <th style="width:100px;">字典：</th>
                <td colspan="3">
                    <input id="dicInfo" name="dicInfo" class="easyui-textbox" missingMessage="元素中文名的近义词，用英文逗号隔开" prompt="元素中文名的近义词，用英文逗号隔开" style="width:90%;"
                           data-options="required:false" />
                </td>
            </tr>
            <tr>
                <th style="width:100px;">释义简介：</th>
                <td colspan="3">
                    <input id="infoBegin" name="infoBegin" data-options="required:true,validType:[length[0,50]]"/>
                </td>
            </tr>
            <tr>
                <th style="width:100px;">释义：</th>
                <td colspan="3">
                    <textarea id="info" style="width:80%;height: 300px"></textarea>
                </td>
            </tr>
            <tr id="rangeParam">
                <th style="width:100px;">最小参考范围：</th>
                <td>
                    <input id="rangeMin" name="rangeMin" class="easyui-textbox" missingMessage="请输入" prompt="请输入" style="width:90%;"
                           data-options="required:false" />
                </td>
                <th style="width:100px;">最大参考范围：</th>
                <td>
                    <input id="rangeMax" name="rangeMax" class="easyui-textbox" missingMessage="请输入" prompt="请输入" style="width:90%;"
                           data-options="required:false" />
                </td>
            </tr>
            <tr id="rangeParam1">
                <th style="width:100px;">参考范围计量单位：</th>
                <td colspan="3">
                    <input id="rangeInfo" name="rangeInfo" class="easyui-textbox" missingMessage="请输入" prompt="请输入" style="width:90%;"
                           data-options="required:false" />
                </td>
            </tr>
            <tr id="rangeParam2">
                <th style="width:100px;">阴阳属性：</th>
                <td colspan="3">
                    <select id="rangeInfos" class="easyui-combobox" name="rangeInfos" data-options="required:true,editable:false">
                        <option value="1">阳</option>
                        <option value="2">阴</option>
                    </select>
                </td>
            </tr>
        </table>
    </div>
</form>
</body>
</html>